All Questions
Tagged with swifttime-limit-exceeded
13 questions
5votes
2answers
596views
Leet Code 139 (Word Break) using a trie with recursion
I was attempting to solve LeetCode 139 - Word Break Given a string s and a dictionary of strings wordDict, return ...
1vote
1answer
216views
Minimum Window Substring in Swift exceeds LeetCode runtime check
This is a popular question on LeetCode: 76. Minimum Window Substring Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in ...
2votes
1answer
3kviews
Dynamic Array Problem (Hacker rank)
I am trying to solve the Dynamic Array problem on HackerRank: Create a list, seqList, of N empty sequences, where each sequence is indexed from 0 to N-1. The elements within each of the N ...
3votes
1answer
528views
Minimum window substring - LeetCode challenge
Below is my code for the “Minimum Window Substring” LeetCode problem in Swift: Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(...
2votes
1answer
3kviews
Sums for list of ranges (CodeFights Basic Skills)
I can solve this problem with a brute force naive solution, but need to optimize it for time. I'm not in school, but trying to learn fundamentals on my own. I know I need to store the sum of the ...
4votes
1answer
846views
Checking whether strings are permutations of each other in Swift
I'm solving this problem on Hacker Earth, just for practice. The exercise is to determine whether two given equal-length strings are permutations of each other. Except for this one test case, which ...
3votes
1answer
164views
Project Euler problem #14 (longest Collatz chain) in Swift
This is my Swift code for finding the starting number, under one million, which produces the longest collatz chain. ...
5votes
2answers
574views
Practical number algorithm
I am trying to write a program to find the practical numbers, from an input from \$1\$ to \$n\$. Practical numbers My code is running correctly but it is extremely slow when calculating numbers ...
8votes
4answers
1kviews
Project Euler problem 14 (longest Collatz sequence) in Swift 3
I was trying to solve Project Euler:Problem 14 using Swift 3, but it takes ages to give me an answer, which is a sign that my code is absolute garbage performance-wise. What could I do to increase the ...
2votes
2answers
3kviews
Swift HackerRank Missing Numbers Challenge
I'm attempting to solve the "Missing Numbers" challenge on HackerRank where I'm tasked with finding missing elements comparing two arrays. Foundation's ...
3votes
3answers
694views
Calculate the sum of all primes less than 2,000,000 in Swift
This is a Swift program I wrote to calculate the sum of primes below 2 million, but it is tediously slow. I am curious about what makes it so slow. My theory is that copying the filtered array is ...
4votes
2answers
4kviews
Swift solution to Leetcode “Longest Substring Without Repeating Characters”
From LeetCode medium 3. Longest Substring Without Repeating Characters: Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", ...
5votes
1answer
271views
Project Euler, Challenge #12 in Swift
The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: 1, 3, 6, 10, 15, 21, 28, ...